<?php

/**
 * UserbankModel 模型
 * Class UserbankModel
 */
class UserbankModel extends BaseModel
{

    public $tableName = "user_bank";
    public $errMsg = '';

    static private $_singleton;

    public function __construct()
    {
        parent::__construct($this->tableName);
    }

    static public function getSingleton()
    {
        if (!self::$_singleton) {
            self::$_singleton = new static();
        }

        return self::$_singleton;
    }

    public function add($data)
    {
        try {
            $selfModel = static::getSingleton();
            return $selfModel->insert([
                'user_id'         => $data['user_id'],
                'bank_id'       => $data['bank_id'],
                'bank_name'       => $data['bank_name'],
                'account_name'   => $data['account_name'],
                'bank_no'    => $data['bank_no'],
                'bank_address'  => $data['bank_address'],
                'bank_branch_name'    => $data['bank_branch_name'],
                'create_time'   => time(),
                'is_default'    => isset($data['is_default'])? $data['is_default']: 0
            ]);
        } catch (Exception $e) {
            $this->errMsg = $e->getMessage();
            return false;
        }
    }
}